seat: improve api to take into account the tool type
authorIgnacio Casal Quinteiro <qignacio@amazon.com>
Thu, 7 Jan 2021 11:27:26 +0000 (12:27 +0100)
committerIgnacio Casal Quinteiro <qignacio@amazon.com>
Thu, 7 Jan 2021 11:50:48 +0000 (12:50 +0100)
Otherwise if we have several tools with the same serial
and hardware id we might match the wrong tool.

gdk/gdkseat.c
gdk/gdkseatdefault.c
gdk/gdkseatprivate.h
gdk/x11/gdkdevicemanager-xi2.c

index 75ef348a2d154d03944c49daa9a9d0443dee56ca..83af3b88a469bed293904c8f6fb2bbcb0bd86dde 100644 (file)
@@ -436,9 +436,10 @@ gdk_seat_tool_removed (GdkSeat       *seat,
 }
 
 GdkDeviceTool *
-gdk_seat_get_tool (GdkSeat *seat,
-                   guint64  serial,
-                   guint64  hw_id)
+gdk_seat_get_tool (GdkSeat          *seat,
+                   guint64           serial,
+                   guint64           hw_id,
+                   GdkDeviceToolType type)
 {
   GdkDeviceTool *match = NULL;
   GList *tools, *l;
@@ -449,7 +450,7 @@ gdk_seat_get_tool (GdkSeat *seat,
     {
       GdkDeviceTool *tool = l->data;
 
-      if (tool->serial == serial && tool->hw_id == hw_id)
+      if (tool->serial == serial && tool->hw_id == hw_id && tool->type == type)
         {
           match = tool;
           break;
index c9595bafdff0a33734e399b72fdf25a97f93c216..2226d36da1674b52654357f5941b98b2e2a6a98b 100644 (file)
@@ -442,7 +442,7 @@ gdk_seat_default_remove_tool (GdkSeatDefault *seat,
 
   priv = gdk_seat_default_get_instance_private (seat);
 
-  if (tool != gdk_seat_get_tool (GDK_SEAT (seat), tool->serial, tool->hw_id))
+  if (tool != gdk_seat_get_tool (GDK_SEAT (seat), tool->serial, tool->hw_id, tool->type))
     return;
 
   g_signal_emit_by_name (seat, "tool-removed", tool);
index 12453896addfd1db24f504085362b4ab6e025069..228740dbaf55df541778684dc0b42e8c8b86ee7a 100644 (file)
@@ -75,9 +75,10 @@ void gdk_seat_tool_removed   (GdkSeat       *seat,
                               GdkDeviceTool *tool);
 
 GdkDeviceTool *
-     gdk_seat_get_tool       (GdkSeat   *seat,
-                              guint64    serial,
-                              guint64    hw_id);
+     gdk_seat_get_tool       (GdkSeat          *seat,
+                              guint64           serial,
+                              guint64           hw_id,
+                              GdkDeviceToolType type);
 
 GdkGrabStatus  gdk_seat_grab             (GdkSeat                *seat,
                                           GdkSurface              *surface,
index 3165205a5f6631156660dca1549d85163c998283..07073ee39560efdf392b8ded2580c558ed48fc94 100644 (file)
@@ -1097,15 +1097,16 @@ handle_property_change (GdkX11DeviceManagerXI2 *device_manager,
       if (ev->what != XIPropertyDeleted &&
           device_get_tool_serial_and_id (device, &serial_id, &tool_id))
         {
+          GdkDeviceToolType tool_type;
+
           seat = gdk_device_get_seat (device);
-          tool = gdk_seat_get_tool (seat, serial_id, tool_id);
+          tool_type = device_get_tool_type (device);
 
-          if (!tool && serial_id > 0)
+          if (tool_type != GDK_DEVICE_TOOL_TYPE_UNKNOWN)
             {
-              GdkDeviceToolType tool_type;
+              tool = gdk_seat_get_tool (seat, serial_id, tool_id, tool_type);
 
-              tool_type = device_get_tool_type (device);
-              if (tool_type != GDK_DEVICE_TOOL_TYPE_UNKNOWN)
+              if (!tool && serial_id > 0)
                 {
                   tool = gdk_device_tool_new (serial_id, tool_id, tool_type, 0);
                   gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool);